<template>
    <div>
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="姓名" prop="name">
    <el-input v-model="ruleForm.name"></el-input>
  </el-form-item>
   <el-form-item label="年龄" prop="age">
    <el-input v-model="ruleForm.age"></el-input>
  </el-form-item>
  <el-form-item label="出生地" prop="resouce">
    <el-select v-model="ruleForm.resouce" placeholder="请输入选择地区">
      <el-option label="湖南" value="hunan"></el-option>
      <el-option label="苏州" value="suzhou"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item label="出生日期" required>
    <el-col :span="11">
      <el-form-item prop="date">
        <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.date1" style="width: 100%;"></el-date-picker>
      </el-form-item>
    </el-col>
    <!-- <el-col class="line" :span="2">-</el-col>
    <el-col :span="11">
      <el-form-item prop="date2">
        <el-time-picker placeholder="选择时间" v-model="ruleForm.date2" style="width: 100%;"></el-time-picker>
      </el-form-item>
    </el-col> -->
  </el-form-item>
  <!-- <el-form-item label="即时配送" prop="delivery">
    <el-switch v-model="ruleForm.delivery"></el-switch>
  </el-form-item> -->
   <el-form-item label="兴趣爱好" prop="hobby">
    <el-checkbox-group v-model="ruleForm.hobby">
      <el-checkbox label="美食" name="type"></el-checkbox>
      <el-checkbox label="运动" name="type"></el-checkbox>
      <el-checkbox label="旅游" name="type"></el-checkbox>
      <el-checkbox label="购物" name="type"></el-checkbox>
    </el-checkbox-group>
  </el-form-item> 
  <el-form-item label="性别" prop="sex">
    <el-radio-group v-model="ruleForm.resource">
      <el-radio label="女"></el-radio>
      <el-radio label="男"></el-radio>
    </el-radio-group>
  </el-form-item>
  <el-form-item label="备注" prop="remark">
    <el-input type="textarea" v-model="ruleForm.remark"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
  </el-form-item>
</el-form>
    </div>
</template>
<script>
  export default {
    data() {
      return {
        ruleForm: {
          name: '',
          age:'',
          resouce: '',
          date: '',
        //   date2: '',
          delivery: false,
          hobby: [],
          sex: '',
          remark: ''
        },
        rules: {
          name: [
            { required: true, message: '请输入姓名', trigger: 'blur' },
            { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
           age: [
            { required: true, message: '请输入年龄', trigger: 'blur' },
          ],
          resouce: [
            { required: true, message: '请选择地区', trigger: 'change' }
          ],
          date: [
            { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
          ],
        //   date2: [
        //     { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
        //   ],
          habbit: [
            { type: 'array', required: true, message: '请至少选择一个兴趣爱好', trigger: 'change' }
          ],
          sex: [
            { required: true, message: '请选择性别', trigger: 'change' }
          ],
         remark: [
            { required: true, message: '请填写备注', trigger: 'blur' }
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>